#include "projectfolder.h"
#include "common.h"

class ProjectFolderPrivate{
	public:
		ProjectFolderPrivate() {}
		~ProjectFolderPrivate() {}
};

ProjectFolder::ProjectFolder(ProjectItem *parent) :
	ProjectItem(parent), O_PRIVATE_CREATE(ProjectFolder)
{
	O_D(ProjectFolder);
	//d->
}

ProjectFolder::~ProjectFolder()
{
	O_PRIVATE_DELETE;
}

QVariantMap ProjectFolder::serialize()
{
	O_D(ProjectFolder);
	QVariantList lst;
	foreach(ProjectItem* i, items())
	{
		QVariantMap m = i->serialize();
		lst.append(i->serialize());
	}

	QVariantMap map = ProjectItem::serialize();
	map.insert("FolderItems", lst);
	return map;
}

void ProjectFolder::deserialize( const QVariantMap& m )
{
	O_D(ProjectFolder);
	ProjectItem::deserialize(m);
	QVariantList lst = m["FolderItems"].toList();
	foreach(QVariant v, lst)
	{
		QVariantMap map = v.toMap();
		QString t = map["type"].toString();
		ProjectItem* i = fromItemType(t);
		if (i != 0)
		{
			i->deserialize(map);
			addItem(i);
		}
	}
}

QWidget* ProjectFolder::widget()
{
	static QLabel* label = 0;
	if (label == 0)
		label = new QLabel(toString());

	return label;
}

bool ProjectFolder::create()
{
	return true;
}
